﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using Xiaov.SmartWeb.Application.SupCan;

namespace Xiaov.SmartWeb.Application.StatisticsReport.YT_TZZB2
{
    public partial class YT_TZZB2 : Xiaov.SmartWeb.Model.BasePage
    {
        protected string nf = DateTime.Now.Year.ToString();
        protected string yf = (DateTime.Now.Month - 1).ToString();
        protected string dwbm = "HB";

        protected void Page_Load(object sender, EventArgs e)
        {
            PM_Filter_Statistical();
            if (!Page.IsPostBack)
            {
                BindDDL();
            }
        }

        protected void BindDDL()
        {
            try
            {
                Statistics.UI.DDL.BindDDL(ddl_Owner, ddl_Year, ddl_Month, PUser.USERDEPT, true);
            }
            catch (Exception ex)
            {

            }
            //从cookies获取默认值
            if (Request.Cookies["UserSelectInfo"] != null)
            {
                ddl_Owner.SelectedValue = Request.Cookies["UserSelectInfo"]["DW"];
                ddl_Year.SelectedValue = Request.Cookies["UserSelectInfo"]["NF"];
                ddl_Month.SelectedValue = Request.Cookies["UserSelectInfo"]["YF"];
            }
            if ((Session["yf"] != null) && (Session["nf"] != null))
            {
                ddl_Month.SelectedValue = Session["yf"].ToString();
                ddl_Year.SelectedValue = Session["nf"].ToString();
            }
            nf = ddl_Year.SelectedValue;
            yf = ddl_Month.SelectedValue;
            dwbm = ddl_Owner.SelectedValue;
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            if (HDData.Value != null && HDData.Value != "")
            {
                ConvertXmlToSql<YT_TZZBModel>.AddUpdateDeleteObject(HDData.Value, "YT_TZZB", false, true, true);

                string yf = ddl_Month.SelectedValue;
                string nf = ddl_Year.SelectedValue;
                OracleParameter[] parameters ={ 
                    new OracleParameter("v_dwbm",OracleType.VarChar,100),
                    new OracleParameter("v_nf",OracleType.VarChar,100),
                    new OracleParameter("v_yf",OracleType.VarChar,100)
                    };
                parameters[0].Value = dwbm;
                parameters[1].Value = nf;
                parameters[2].Value = yf;
                OracleDataReader odr = Maticsoft.DBUtility.DbHelperOra.RunProcedure("p_cj_yt_tzzb_compute", parameters);
                odr.Close();
            }
        }

        protected void btnGenData_Click(object sender, EventArgs e)
        {
            string yf = ddl_Month.SelectedValue;
            string nf = ddl_Year.SelectedValue;
            //调用过程             
            OracleParameter[] parameters1 ={ 
                    new OracleParameter("v_dwbm",OracleType.VarChar,100),
                    new OracleParameter("v_nf",OracleType.VarChar,100),
                    new OracleParameter("v_yf",OracleType.VarChar,100)
                    };
            parameters1[0].Value = dwbm;
            parameters1[1].Value = nf;
            parameters1[2].Value = yf.PadLeft(2, '0');
            OracleDataReader odr1 = Maticsoft.DBUtility.DbHelperOra.RunProcedure("p_cj_yt_tzzb_create", parameters1);
            odr1.Close();

            OracleParameter[] parameters2 ={ 
                    new OracleParameter("v_dwbm",OracleType.VarChar,100),
                    new OracleParameter("v_nf",OracleType.VarChar,100),
                    new OracleParameter("v_yf",OracleType.VarChar,100)
                    };
            parameters2[0].Value = dwbm;
            parameters2[1].Value = nf;
            parameters2[2].Value = yf.PadLeft(2, '0');
            OracleDataReader odr2 = Maticsoft.DBUtility.DbHelperOra.RunProcedure("p_cj_yt_tzzb_qs", parameters2);
            odr2.Close();

            OracleParameter[] parameters3 ={ 
                    new OracleParameter("v_dwbm",OracleType.VarChar,100),
                    new OracleParameter("v_nf",OracleType.VarChar,100),
                    new OracleParameter("v_yf",OracleType.VarChar,100)
                    };
            parameters3[0].Value = dwbm;
            parameters3[1].Value = nf;
            parameters3[2].Value = yf.PadLeft(2, '0');
            OracleDataReader odr3 = Maticsoft.DBUtility.DbHelperOra.RunProcedure("p_cj_yt_tzzb_compute", parameters3);
            odr3.Close();
        }

        protected void btn_Clear_Click(object sender, EventArgs e)
        {
            string nf = ddl_Year.SelectedValue;
            string yf = ddl_Month.SelectedValue;
            string sql = string.Format("delete from yt_tzzb where nf='{0}' and yf={1} and dwbm='{2}'", nf, yf, "HB");
            try
            {
                Maticsoft.DBUtility.DbHelperOra.ExecuteSql(sql);
            }
            catch
            {
            }
        }
    }
}